<template>
  <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
    <div class="find-container">
      <van-nav-bar title="发现" />
      <div class="main-box">
        <!-- 面试技巧区域 -->
        <div class="interview-box">
          <!-- 标题区域 -->
          <div class="title-box">
            <div class="title">
              面试技巧
            </div>
            <div class="arrow-box" @click="$router.push('/technicList')">
              <span>查看更多</span>
              <i class="iconfont iconicon_more"></i>
            </div>
          </div>
          <!-- 列表区域 -->
          <div class="interview-list">
            <van-skeleton v-if="!technicList" title :row="6" />
            <technicItem
              v-for="item in technicList"
              :key="item.id"
              @itemClick="$router.push(`/technicDetail/${item.id}`)"
              :item="item"
            ></technicItem>
          </div>
        </div>
        <!-- 市场数据 -->
        <chartList></chartList>
        <!-- 面经分享 -->
        <div class="experience-box">
          <!-- 标题区域 -->
          <div class="title-box">
            <div class="title">
              面经分享
            </div>
            <div class="arrow-box" @click="$router.push('/shareList')">
              <span>查看更多</span>
              <i class="iconfont iconicon_more"></i>
            </div>
          </div>
          <!-- 列表 -->
          <div class="experience-list">
            <shareItem
              v-for="item in shartList"
              :key="item.id"
              @shareItemClick="$router.push(`/shareDetail/${item.id}`)"
              :item="item"
            ></shareItem>
          </div>
        </div>
      </div>
    </div>
  </van-pull-refresh>
</template>

<script>
import { articlesTechnic, articlesShare } from '../../api/api'
// 分享列表项
import shareItem from '../shareList/shareItem'
// 技术列表项
import technicItem from '../technicList/technicItem'
// 数据统计列表
import chartList from './chartList'

export default {
  name: 'find',
  components: {
    shareItem,
    technicItem,
    chartList
  },
  data () {
    return {
      limit: 3,
      // 面试技巧
      technicList: '',
      // 分享面经
      shartList: [],
      // 是否正在加载
      isLoading: false
    }
  },
  methods: {
    async getData () {
      this.$toast.loading()
      // 面试技巧获取
      const technicRes = await articlesTechnic({ limit: this.limit })
      this.$toast.clear()
      // 处理封面地址
      technicRes.data.list.forEach(v => {
        if (v.cover) {
          v.cover = process.env.VUE_APP_URL + v.cover
        }
      })
      this.technicList = technicRes.data.list

      // 面经分享获取
      const shareRes = await articlesShare({ limit: this.limit })
      // 处理封面地址
      shareRes.data.list.forEach(v => {
        if (v.cover) {
          v.cover = process.env.VUE_APP_URL + v.cover
        }
        if (v.author) {
          v.author.avatar = process.env.VUE_APP_URL + v.author.avatar
        }
      })
      this.shartList = shareRes.data.list
    },
    async onRefresh () {
      await this.getData()
      this.isLoading = false
    }
  },
  created () {
    this.getData()
  }
}
</script>

<style lang="less">
.van-nav-bar__title {
  font-size: 18px;
}
.find-container {
  .main-box {
    background: @bgColor;
  }
  .interview-box {
    background: @whiteColor;
    padding: 0 15px;
    margin-bottom: 10px;
  }
  .title-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 69px;
    .title {
      font-size: 18px;
      font-weight: 500;
      color: @fontColor;
    }
    .arrow-box {
      span {
        font-size: 400;
        font-size: 14px;
        color: @secFontColor;
      }
    }
  }
  .interview-list {
    .item {
      padding-bottom: 29px;
      display: flex;
      min-height: 67px;
      .content {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .title {
          font-size: 16px;
          font-weight: 500;
          color: @fontColor;
        }
        .info {
          color: @minorFontColor;
          font-size: 12px;
          display: flex;
          margin-top: 10px;
          align-items: center;
          .time {
            flex: 1;
          }
          .iconfont {
            margin-right: 8px;
            font-size: 16px;
            line-height: 1;
          }
          .see {
            margin-right: 23px;
            display: flex;
            align-items: center;
          }
          .zan {
            display: flex;
            align-items: center;
          }
        }
      }
      .cover {
        width: 113px;
        height: 75px;
        margin-left: 16px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .experience-box {
    padding: 0 15px;
    background: @whiteColor;
    .item {
      padding-top: 16px;
      padding-bottom: 28px;
      .title {
        font-size: 16px;
        color: @fontColor;
        margin-bottom: 12px;
      }
      .content {
        color: @secFontColor;
        font-size: 14px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }
      .info-box {
        margin-top: 20px;
        display: flex;
        align-items: center;
        font-size: 12px;
        color: @minorFontColor;
        .userinfo {
          flex: 1;
          display: flex;
          align-items: center;
        }
        img {
          width: 22px;
          height: 22px;
          border-radius: 50%;
          margin-right: 10px;
        }
        .time {
          margin-right: 21px;
        }
        .mes {
          margin-right: 23px;
        }
        .iconfont {
          margin-right: 7px;
        }
        .mes,
        .zan {
          display: flex;
          align-items: center;
        }
      }
    }
  }
}
</style>
